#include<iostream>
#include<vector>
using namespace std;
//水果盛篮问题
class Solution {
public:
    int totalFruit(vector<int>& fruits) 
    {
        vector<int> hash(100001,0);
        int ret = 0;
        int n = fruits.size();
        for (int left = 0, right = 0, kinds = 0; right < n; right++)
        {
            if (hash[fruits[right]] == 0)
                kinds++;
            hash[fruits[right]]++;
            while (kinds > 2)
            {
                hash[fruits[left]]--;
                if (hash[fruits[left]] == 0)
                    kinds--;
                left++;
            }
            ret = max(ret, right - left + 1);
        }
        return ret;
    }
};
int main()
{
    Solution s1;
    vector<int> f1 = {0,1,2,2};
    vector<int> f2 = {1,2,3,2,2};
    cout << s1.totalFruit(f1) << endl;
    cout << s1.totalFruit(f2) << endl;
	return 0;
}